﻿
// **************************************************************************
//    Class Created by Mick Doherty (Dotnetrix) May 2010
//    http://dotnetrix.co.uk/
//
//    ...for GlassUI (an AeroGlass UI Library)
//    http://glassui.codeplex.com/
// **************************************************************************

using System;
using System.Security.Permissions;
using System.Windows.Forms;
using System.Windows.Forms.Design;

namespace GlassUI.Design
{
    public class NonClientControlDesigner : ScrollableControlDesigner
    {
        protected override bool GetHitTest(System.Drawing.Point pt)
        {
            if (!this.Control.ClientRectangle.Contains(this.Control.PointToClient(pt)))
                return false;
            return base.GetHitTest(pt);
        }

        [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
            if (m.Msg == (int)NativeMethods.USER32.WindowMessage.WM_NCHITTEST)
            {
                //select Control when non client area clicked.
                if (m.Result.ToInt32() == (int)NativeMethods.USER32.NCHITTESTRESULT.BORDER)
                    m.Result = (IntPtr)NativeMethods.USER32.NCHITTESTRESULT.CLIENT;
            }
        }
    }
}
